package cn.tedu.spring.example;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class TestUser {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        /**
         * 方式1: 通过new方式
         */
        User1 user1 = new User1();
        user1.userRun();

        /**
         * 方式2: 通过反射方式
         */
        Class zz = Class.forName("cn.tedu.spring.example.User1");
        User1 user2 = (User1) zz.newInstance();
        user2.userRun();

        /**
         * 方式3:通过Spring框架创建对象
         * Windows[键盘上无Fn按键]: Ctrl + Shift + Alt + c
         * Windows[键盘上有Fn按键]:Fn + Ctrl + Shift + Alt + c
         * Mac: Command + Shift + c
         */
        ApplicationContext context = new AnnotationConfigApplicationContext("cn.tedu.spring.example");
        User1 user3 = context.getBean(User1.class);
        user3.userRun();
    }
}
